<!--
@name:pointerList
@author:Zhenglei
@date:14:15
@description:pointerList
@update:2022/8/2514:15
-->
<template>
  <div class="pd-20">
    <el-input v-model="queryData.indicationName"
              placeholder="请输入指征名称"
              clearable
              @clear="handleOption('select')"
              class="w-200"/>

    <el-select v-model="queryData.indicationType"
               clearable
               @change="handleOption('select')"
               placeholder="请选择类型">
      <el-option v-for="item in typeDataSource"
                 :key="item.id"
                 :label="item.name"
                 :value="item.id">
      </el-option>
    </el-select>

    <el-button type="primary"
               @click="handleOption('select')">查询
    </el-button>
    <el-button type="primary"
               @click="handleOption('add')">新增
    </el-button>
    <element-table class="mt-20"
                   :columns="columns"
                   :data="tableData"
                   v-loading="loading"
                   pager
                   :pageTotal="pageTotal"
                   :pageIndex="pageIndex"
                   :pageSize="pageSize"
                   @handleChangePage="handleChangePage">
      <template v-slot:option="{row}">
        <el-button type="primary"
                   @click="handleOption('edit', row)">编辑
        </el-button>

        <el-button type="info"
                   v-if="row.isSetScore===1"
                   @click="handleOption('score', row)">评分配置(已配置)
        </el-button>
        <el-button type="warning"
                   v-else
                   @click="handleOption('score', row)">评分配置(未配置)
        </el-button>
        <el-button type="primary"
                   @click="handleOption('condition', row)">条件判断配置
        </el-button>
        <el-button type="danger"
                   @click="handleOption('del', row)">删除
        </el-button>
      </template>
    </element-table>
    <dialog-point v-if="showDialog" :visible.sync="showDialog" :dataObj="dataObj"/>
    <dialog-score v-if="showScoreDialog" :visible.sync="showScoreDialog" :dataObj="dataObj"/>
    <dialog-condition v-if="showConditionDialog" :visible.sync="showConditionDialog" :dataObj="dataObj"/>
  </div>

</template>

<script>
  import ElementTable from "../../../../base/ElementTable";
  import dialogPointer from "./dialogPointer";
  import dialogScore from "./dialogScore";
  import dialogConditionConfig from "./dialogConditionConfig";

  export default {
    name: "pointerList",
    data() {
      return {
        queryData: {
          indicationName: '',
          indicationType: ''
        },
        pageSize: 20,
        pageIndex: 1,
        pageTotal: 0,
        tableData: [],
        loading: false,
        showDialog: false,
        showScoreDialog: false,
        showConditionDialog: false,
        dataObj: {},
        typeDataSource: [
          // {
          //   name: '病种指标',
          //   id: 1
          // },
          {
            name: '量表指标',
            id: 2
          },
          {
            name: '检测指标',
            id: 3
          },
          {
            name: '基础数据',
            id: 4
          }
        ],
        columns: [
          {
            label: '指征名称',
            prop: 'indicationName',
            align: 'center',
          }, {
            label: '类型',
            prop: 'indicationType',
            align: 'center',
            formatter: (row, cellValue) => {
              // if (row.indicationType === 1) return '病种指标'
              if (row.indicationType === 2) return '量表指标'
              if (row.indicationType === 3) return '检测指标'
              if (row.indicationType === 4) return '基础数据'
            },
          }, {
            label: '操作',
            prop: 'option',
            align: 'center',
            isSlot: true
          }
        ]

      }
    },
    created() {
      this.getList()
    },
    methods: {
      handleOption(op, row) {
        switch (op) {
          case 'add':
            this.dataObj = {}
            this.showDialog = true
            break;
          case 'edit':
            this.dataObj = row
            this.showDialog = true
            break
          case 'select':
            this.pageIndex = 1
            this.getList();
            break
          case 'score':
            this.dataObj = row
            this.showScoreDialog = true
            break
          case 'condition':
            this.dataObj = row
            this.showConditionDialog = true
            break
          case 'del':
            this.$confirm('是否要确认?', '提示', {
              type: 'warning'
            }).then(() => {
              this.post(this.api.healthMap.delIndication, {
                id: row.id
              }).then((res) => {
                if (res.data.code === '200') {
                  this.$message.success('删除成功!');
                  this.getList()
                }
              })
            })
            break

        }

      },
      getList() {
        this.loading = true
        this.post(this.api.healthMap.getIndicationList, {
          pageIndex: this.pageIndex - 1,
          pageSize: this.pageSize,
          ...this.queryData
        }).then((res) => {
          this.loading = false
          if (res.data.code === '200') {
            this.tableData = res.data.object
            this.pageTotal = res.data.totalNum
          }
        })
      },
      // 分页
      handleChangePage(page) {
        this.pageIndex = page;
        this.getList();
      },
    },
    components: {
      'element-table': ElementTable,
      'dialog-point': dialogPointer,
      'dialog-score': dialogScore,
      'dialog-condition': dialogConditionConfig,
    }
  }
</script>

<style scoped>

</style>
